package src.com.hpu.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import com.hpu.bean.FailScore;
import com.hpu.bean.Score;

public class FailScoreParser {

	public FailScore parse(String parseString) {
		List<Score> untilFailScore = new ArrayList<>();
		List<Score> onceFailScore = new ArrayList<>();

		try {
			JSONArray array = new JSONArray(parseString);
			for (int m = 0; m < array.length(); m++) {
				JSONArray array1 = array.getJSONArray(m);
				for (int i = 0; i < array1.length(); i++) {
					JSONArray arr = array1.getJSONArray(i);
					String number = arr.getString(0);
					String order = arr.getString(1);
					String subject = arr.getString(2);
					String credit = arr.getString(3);
					String value = arr.getString(5);
					String term = arr.getString(6);
					if (m == 0)
						untilFailScore.add(new Score(credit, subject, term,
								number, order, value));
					if (m == 1)
						onceFailScore.add(new Score(credit, subject, term,
								number, order, value));
				}
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return new FailScore(untilFailScore, onceFailScore);
	}

}
